# -*- coding: utf-8 -*-
import time

from src.handler.AbstractHandler import AbstractHandler
from src.handler.hongbao import HongBaoConfig
from src.handler.hongbao.SoftStoneProcess import SoftStoneProcess


class SoftStoneTaskHandler(AbstractHandler):
    def _setup_arg(self, subparsers):
        # 添加关闭计算机的子命令
        parser_hong_bao = subparsers.add_parser('ss', help='转正')
        parser_hong_bao.add_argument('--second', '-s', type=int, default=5,
                                     help='Countdown in seconds before shutdown (default: 30)')
        parser_hong_bao.add_argument('--minute', '-m', type=int, default=60,
                                     help='Countdown in seconds before shutdown (default: 30)')
        parser_hong_bao.set_defaults(func=self.do_process)

    def _check(self, args):
        """检查参数是否有效"""
        return True

    def _process(self, args):
        config_params = []

        start_time = time.time()
        run_duration = args.minute * 60

        while time.time() - start_time < run_duration:
            time.sleep(3)
            process_x = SoftStoneProcess(self.config, config_params)
            process_x.process()
